package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api("套餐相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;








    /*
    * 套餐分页查询
    * */

    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result page(SetmealPageQueryDTO dto){
        log.info("套餐分页查询 :{}",dto);
        PageResult p =setmealService.page(dto);

        return Result.success(p);
    }
    /*
     * 修改套餐
     * */

    @ApiOperation("修改套餐")
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("传入参数为; {}",setmealDTO);

        setmealService.update(setmealDTO);

        return Result.success();
    }


    /*
     * 根据id查询套餐相当于修改回显
     * */

    @ApiOperation("根据id查询套餐")
    @GetMapping("{id}")
    public Result selectById(@PathVariable Long id){
        log.info("传入ID为：{}",id);
        SetmealVO vo=setmealService.selectById(id);
        return Result.success(vo);
    }

    /*
     * 新增套餐
     * */

    @ApiOperation("新增套餐")
    @PostMapping
    public Result insert(@RequestBody SetmealDTO dto){
        log.info("传入参数为： {}",dto);
        setmealService.insert(dto);
        return Result.success();
    }

    /*
     * 批量删除套餐
     * */

    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("传入参数为：{}",ids);
        setmealService.deleteBatch(ids);
        return Result.success();
    }



    /**
     * 套餐起售停售
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("套餐起售停售")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        setmealService.startOrStop(status, id);
        return Result.success();
    }




}
